package mf.tools;

/** Object for representing a stack command used for the traversal of the derivation tree. */
public class Command {

	//constants for directions 
	public static final int LEFT_DIRECTION = 0;
	public static final int RIGHT_DIRECTION = 1;
	public static final int UP_DIRECTION = 2;
	
	//attributes
	private Integer variable;
	private Integer length;
	private Integer direction;
	
	/** Create new command with variable v, derivation length l and direction d. */
	public Command(Integer v, Integer l, Integer d) {
		variable = v;
		length = l;
		direction = d;
	}
	
	/** Gets the variable. */
	public Integer variable() {
		return variable;
	}
	
	/** Gets the derivation length. */
	public Integer length() {
		return length;
	}
	
	/** Gets the direction. */
	public Integer direction() {
		return direction;
	}
	
	/** Returns true if two commands have the same variable, the same derivation length and the same direction. */
	public boolean equals(int v, int l, int d) {
		return variable == v && length == l && direction == d;
	}
	
	/** Returns a string representation of the command. */
	public String toString() {
		String ret = "(" + variable + ", " + length + ", ";
		
		switch (direction) {
		case LEFT_DIRECTION:
			ret += "L";
			break;
		case RIGHT_DIRECTION:
			ret += "R";
			break;
		case UP_DIRECTION:
			ret += "U";
			break;
		}
		
		return ret + ")";
	}
}
